<template>
    <table>
        <tr>
            <td>优惠券标题</td>
            <td>
                <input type="text" v-model="states.title">
            </td>
        </tr>
        <tr>
            <td>门店</td>
            <td>
                <select v-model="states.stoid">
                    <option value="">请选择</option>
                    <option value="1">白马弄堂</option>
                    <option value="2">放学等我</option>
                    <option value="3">某某</option>
                    <option value="4">山茶花</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>开始时间</td>
            <td>
                <input type="date" v-model="states.sdate">
            </td>
        </tr>
        <tr>
            <td>结束时间</td>
            <td>
                <input type="date" v-model="states.edate">
            </td>
        </tr>
        <tr>
            <td>库存数量</td>
            <td>
                <input type="text" v-model="states.kcount">
            </td>
        </tr>
        <tr>
            <td>金额</td>
            <td>
                <input type="text" v-model="states.ymondy">
            </td>
        </tr>
        <tr>
            <td>描述</td>
            <td>
                <textarea cols="30" rows="3" v-model="states.misoshu"></textarea>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="添加" @click="add">
            </td>
        </tr>
    </table>
  </template>
  
  <script setup lang="ts">
  import{reactive, toRefs} from 'vue'
  import axios from 'axios'
  import {useRouter,useRoute} from 'vue-router'
  const route=useRoute()
  const router=useRouter()

  let data=reactive({
    states:{
        title:'',
        stoid:'',
        sdate:'',
        edate:'',
        kcount:'',
        ymondy:'',
        misoshu:''
    }
  })
  let{states} =toRefs(data)

  const add=()=>{
    if(states.value.title==""){
        alert("优惠券标题不能为空")
        return;
    }
    if(states.value.stoid==""){
        alert("门店不能为空")
        return;
    }
    if(states.value.sdate==""){
        alert("开始时间不能为空")
        return;
    }
    if(states.value.edate==""){
        alert("结束时间不能为空")
        return;
    }
    if(states.value.kcount==""){
        alert("库存数量不能为空")
        return;
    }
    if(states.value.ymondy==""){
        alert("金额不能为空")
        return;
    }
    if(states.value.misoshu==""){
        alert("描述不能为空")
        return;
    }
    let obj={
        "title": states.value.title,
  "storeid": states.value.stoid,
  "stime": states.value.sdate,
  "etime": states.value.edate,
  "kcount": states.value.kcount,
  "ymoney": states.value.ymondy,
  "mshu": states.value.misoshu,
  "states": 1,
  "isdete": false
    }
    axios({
        url:'/api/Store/Adddis',
        method:'post',
        data:obj
    })
    .then(res=>{
        console.log(res)
        if(res.data.data==1){
            alert("添加优惠券成功")
            router.push('/showdis')
        }else{
            alert("添加优惠券失败")
        }
    })
  }
  </script>
  
  <style scoped>
  
  </style>